package cn.heapstack.jpa.domain;

import javax.persistence.AttributeOverride;
import javax.persistence.AttributeOverrides;
import javax.persistence.Column;
import javax.persistence.Embedded;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.Transient;

@Entity(name = "MPO_Customer_Using_EmbeddedID")
public class Customer2 {

	private String firstName;
	private CustomerPK pk;
	private CustomerType customerType;
	private Address address;

	/**
	 * * 使用Embedded的方法，和@EmbeddedId用法类似 * *
	 * 这种方式，address的三个属性都将存在MPO_Customer_Using_EmbeddedID表中 *
	 * 这个用法和@SecondaryTable形成个对比 * * @return
	 */
	@Embedded
	public Address getAddress() {
		return address;
	}

	public void setAddress(Address address) {
		this.address = address;
	}

	/**
	 * * @Enumerated(EnumType.ORDINAL) 存在数据库的是数字 * * <property
	 * name="hibernate.hbm2ddl.auto" value="update" /> *
	 * 如果自动生成数据库的话，CustomerType字段将是INTERGER类型的 * * @Enumerated(EnumType.STRING)
	 * 存在数据库的是字符串 * @return
	 */
	@Enumerated(EnumType.STRING)
	public CustomerType getCustomerType() {
		return customerType;
	}

	public void setCustomerType(CustomerType customerType) {
		this.customerType = customerType;
	}

	public String getFirstName() {
		return firstName;
	}

	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	@EmbeddedId
	@AttributeOverrides( {
			@AttributeOverride(name = "lastName", column = @Column(name = "CUSTOMER_Override_LASTNAME")),
			@AttributeOverride(name = "ssn", column = @Column(name = "CUSTOMER_Override_SSN")) })
	public CustomerPK getPk() {
		return pk;
	}

	public void setPk(CustomerPK pk) {
		this.pk = pk;
	}

	@Transient
	public String getLastName() {
		return this.pk.getLastName();
	}

	@Transient
	public long getSsn() {
		return this.pk.getSsn();
	}

}
